/*Violence enumeration . The time complex is O(n^2)*/
#include<iostream> 
#include<stdio.h>
#include<stdlib.h>

using namespace std;

int main()
{
    int n,a[10001],i,j,k,l;
    while(cin>>n && n!=0 )
    {
        for(i=0;i<n;i++)
          cin>>a[i];
        int sum , maxSofar = 0;
        int left =0 , right = n-1;
        bool flag = false;
        for(i=0;i<n;i++)
        {
            sum = 0;
            for(j=i;j<n;j++)
            {
                sum += a[j];
                if( sum > maxSofar )  
                {
                     flag = true; 
                     maxSofar = sum;
                     left = i;
                     right = j;
                }             
            }
        }//for                
        if( flag ) cout<<maxSofar<<" "<<a[left]<<" "<<a[right]<<endl;
        else 
        {
            /* all of the data are less than 0 */      
            int count=0;
            for(i=0;i<n;i++)
            {
                if( a[i]<0 )   count++;
            }
            if(count==n)   printf("0 %d %d\n",a[0],a[n-1]);
        
            /* some are less than 0 and some are equal to 0 */
            bool flag = false , flag1 = false;
            for(i=0;i<n;i++)
            {
                if(a[i]>0 )    { flag = true; break; }
                else if(a[i]==0) { flag1 = true; }
            }
            if( !flag && flag1 ) { printf("0 0 0\n");continue;}
        }
    }//while
    
    //system("pause");
    return 0;
}
